<?php
include("../common/connect.php");
session_start();
$userid=$_SESSION["userid"];
$query="select * from wanna where userid != '$userid';";


$result = mysql_query($query) or die("Query failed");
$rows_sum=@mysql_num_rows($result);
$makerstr="";
$eatCount = 0;
$pickupCount = 0;
$shoppingCount = 0;
for($i=0; $i<$rows_sum; $i++)
{
	@mysql_data_seek($result, $i);
	$data=@mysql_fetch_array($result);
	$wannaType=$data['wannaType'];
	$wannaDescription=$data['WannaDescription'];
	$latitude=$data['latitude'];
	$longtitude=$data['longtitude'];
    $makerstr=$makerstr."    var makerlng".$i." = new google.maps.LatLng(".$latitude.", ".$longtitude.");\r\n";
    $makerstr=$makerstr."    var marker".$i." = new google.maps.Marker({position: makerlng".$i.",map:null,title:\"".$i."\"});\r\n";
    if ($wannaType==1){
    	$makerstr=$makerstr."    eatMarkersArray.push(marker".$i.");\r\n";
    	$eatCount++;
    }else if($wannaType==2){
    	$makerstr=$makerstr."    pickupMarkersArray.push(marker".$i.");\r\n";
    	$pickupCount++;
	}else if($wannaType==3){
    	$makerstr=$makerstr."    shoppingMarkersArray.push(marker".$i.");\r\n";
    	$shoppingCount++;
	}
	$makerstr=$makerstr."    contentString = '<div id=\"content\">'+ \r\n";
    $makerstr=$makerstr."                    '<div id=\"siteNotice\"> </div>'+\r\n";
    
    $makerstr=$makerstr."                    '<h1 id=\"firstHeading\" class=\"firstHeading\">Wanna</h1>'+\r\n";
    $makerstr=$makerstr."                    '<div id=\"bodyContent\">'+ \r\n";
    $makerstr=$makerstr."                    '<p><b>Wanna</b>, also referred to ' + \r\n";
    $makerstr=$makerstr."                    '<b> ".$wannaDescription." </b>'+ \r\n";
    $makerstr=$makerstr."                    '<a href=\"http://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194\">a</a>'+ \r\n";
    $makerstr=$makerstr."                    '</p> </div> </div>'; \r\n";

	$makerstr=$makerstr."    var infowindow".$i." = new google.maps.InfoWindow({ \r\n";
    $makerstr=$makerstr."			content: contentString\r\n";
	$makerstr=$makerstr."		}); \r\n";
	
	$makerstr=$makerstr."    google.maps.event.addListener(marker".$i.", 'click', function() { \r\n";
  	$makerstr=$makerstr."		infowindow".$i.".open(map,marker".$i.");\r\n";
	$makerstr=$makerstr."		});\r\n \r\n";
}

?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
  html { height: 100% }
  body { height: 100%; margin: 0px; padding: 0px }
  #map_canvas { height: 100% }
</style>
<!--<script type="text/javascript"
    src="https://maps.google.com/maps/api/js?sensor=false">
    </script>
    -->
<script type="text/javascript" src="mapapi3.8.6.js"></script>
<script type="text/javascript">
  var map;
  var eatMarkersArray = [];
  var pickupMarkersArray = [];
  var shoppingMarkersArray = [];
  var contentString;
  
  function initialize() {
    var latlng = new google.maps.LatLng(40.0053681, 116.4769563);
    var myOptions = {
      zoom: 12,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    map = new google.maps.Map(document.getElementById("map_canvas"),
        myOptions);
    	<?php
echo $makerstr;
    	?>
    showMyOverlays();
  }
    
  function addMarker(markersArray,location) {
      marker = new google.maps.Marker({
        position: location,
        map: null
      });
      markersArray.push(marker);
    }
	// Removes the overlays from the map, but keeps them in the array
  function clearOverlays() {
    if (eatMarkersArray) {
      for (i in eatMarkersArray) {
    	  eatMarkersArray[i].setMap(null);
      }
    }
    if (pickupMarkersArray) {
        for (i in pickupMarkersArray) {
        	pickupMarkersArray[i].setMap(null);
        }
      }
    if (shoppingMarkersArray) {
        for (i in shoppingMarkersArray) {
        	shoppingMarkersArray[i].setMap(null);
        }
      }
    
  }

  // Shows any overlays currently in the array
  function showOverlays(markersArray) {
    if (markersArray) {
      for (i in markersArray) {
        markersArray[i].setMap(map);
      }
    }
  }
    // Shows any overlays currently in the array
  function showMyOverlays() {
	  clearOverlays();
	  //alert("abc");
    if (document.getElementById("eatCheckbox").checked==true) {
    	//alert("1");
      showOverlays(eatMarkersArray);
    }
	if (document.getElementById("pickupCheckbox").checked ==true) {
		//alert("2");
      showOverlays(pickupMarkersArray);
    }
	if (document.getElementById("shoppingCheckbox").checked ==true) {
		//alert("3");
      showOverlays(shoppingMarkersArray);
    }
  }
</script>
</head>
<body onLoad="initialize()">
<div>

    <form name="form1" method="post" action="">
      <table width="100%" border="1">
        <tr>
        <th scope="col">选择哪个呢？&nbsp;</th>
          <th scope="col"> 一起吃饭(<?php echo $eatCount?>)：
      <input id="eatCheckbox" type="checkbox" onClick="showMyOverlays();" value="checked" checked>&nbsp;</th>
          <th scope="col">搭顺风车(<?php echo $pickupCount?>)：<input id="pickupCheckbox" type="checkbox" onClick="showMyOverlays();" value="checked" checked>&nbsp;</th>
          <th scope="col">一起购物(<?php echo $shoppingCount?>)：<input id="shoppingCheckbox" type="checkbox" onClick="showMyOverlays();" value="checked" checked>&nbsp;</th>
          
          <th scope="col">&nbsp;</th>
        </tr>
      </table>
     
      
      
      
    </form>
</div> 
  <div id="map_canvas" style="width:100%; height:80%"></div>

</body>
</html>

